{% extends 'base.html' %}

{% load switchuser %}
{% load url from future %}

{% block head_title %}Switch-User{% endblock %}

{% block content %}
    {% if not su_state %}
        <div class="alert alert-danger">
            Error: the <tt>su_state</tt> context processor was not found. Is
            <tt>"django_switchuser.context_processors.su_state"</tt> in your list
            of <tt>TEMPLATE_CONTEXT_PROCESSORS</tt>?
        </div>
    {% else %}
        {% if su_state.is_active %}
            <div class="alert alert-success">
                Currently logged in as: <em>{% su_user_short_label su_state.active_user %}</em>
            </div>
        {% endif %}
        <div align="center" class="well">
            <form method="POST" action="{% url "su-login" %}?next={{ next }}">
                {% csrf_token %}
                <label for="user_id">Login as:</label>
                <p>
                <div class="field-container" style="width:75%">
                    <select id="user_id" name="user_id"></select>
                </div>
                </p>
                <input class="btn btn-success btn-large" type="submit" value="Switch-User"/>
            </form>
            <hr>
            {% include "su/logout_form.html" %}
        </div>
    {% endif %}

    <script>

        $('document').ready(function () {
            $("#user_id").select2({
                width: "100%",
                ajax: {
                    url: '/user_lookup/',
                    delay: 250
                },
                cache: true,
                minimumInputLength: 1
            });
        });

    </script>
{% endblock %}
